home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3b.arc / PMDEV.ARC / PMAUXFN.C < prev    next >
C/C++ Source or Header  |  1989-02-14  |  4KB  |  149 lines

  1. /*
  2.  * PMAUXFN - function support module for PMAUX
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define INCL_PM
  11. #include <os2.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <ttycls.h>
  15. #include "pmaux.h"
  16.  
  17. /* set the window handle (might be NULL) into OS2.ini */
  18. BOOL SetOS2Ini(HWND hWnd)
  19. {
  20.     char buf[30];
  21.     return(WinWriteProfileString(hAB,szAppName,"hWnd",ltoa((LONG)hWnd,buf,10)));
  22. }
  23.  
  24. /* respond to menu commands */
  25. void NEAR WndCommand(HWND hWnd, USHORT wParam)
  26. {
  27.  
  28.     HWND hMenu;
  29.  
  30.     switch (wParam) {
  31.     case IDM_CLEAR:
  32.         TTYClear(&MWnd);
  33.         break;
  34.         
  35.         case IDM_CRONLF:
  36.         MWnd.CRonLF = (MWnd.CRonLF ? FALSE : TRUE);    /* toggle parameter */
  37.         hMenu = WinWindowFromID(hwndFrame, FID_MENU);  /* get menu */
  38.       /* set or remove check mark on menu */
  39.          WinSendMsg(hMenu, MM_SETITEMATTR, MPFROM2SHORT(wParam, TRUE),
  40.               MPFROM2SHORT(MIA_CHECKED, MWnd.CRonLF ? MIA_CHECKED : 0));
  41.         break;
  42.  
  43.     case IDM_ABOUT:        /* display about box */
  44.         WinDlgBox(HWND_DESKTOP, hWnd, AboutBoxProc, NULL, DT_ABOUT, NULL);
  45.         break;
  46.     }
  47. }
  48.  
  49. /* send the received buffer to the display */
  50. void NEAR DispatchString(HWND hWnd, MPARAM mp1, MPARAM mp2)
  51. {
  52.  
  53. #define LBUFLEN 80
  54.  
  55.     BYTE buf[LBUFLEN];
  56.     int len, i, count;
  57.     BYTE FAR *bufptr;
  58.     SEL sel;
  59.  
  60.     len = (int)LOUSHORT(mp1);    /* read the length */
  61.     sel = (SEL)LOUSHORT(mp2);    /* get the selector of the shared buffer */
  62.     bufptr = MAKEP(sel,0);    /* make it into a pointer */
  63.  
  64.     if (DosGetSeg(sel) == 0) {    /* access the shared buffer */
  65.     while (len > 0) { /* read and dispatch each part of buffer until done */                                
  66.         count = min(len, LBUFLEN);        
  67.             for (i = 0; i < count; i++)
  68.             buf[i] = *bufptr++;
  69.             TTYDisplay(&MWnd, (short)count, buf);
  70.         len -= count;
  71.     }
  72.     }
  73.     else    /* something wrong, ring the bell */
  74.     WinAlarm(HWND_DESKTOP, WA_WARNING);
  75. }
  76.  
  77. /* repaint the window if needed */
  78. void NEAR MainWndPaint(HWND hWnd, HPS hPS, short top, short bottom)
  79. {
  80.  
  81. /* 
  82.   If Microsoft ever gets WinQueryWindowPos working correctly, then
  83.   replace the line 'if (WindowIsIconic(hWnd))' with the following: 
  84. */
  85. /*
  86.     SWP swp;
  87.  
  88.     WinQueryWindowPos(hWnd, &swp);
  89.  
  90.     if ((swp.fs & SWP_MINIMIZE) && (!(swp.fs & SWP_MAXIMIZE))) {
  91. */
  92.  
  93.     if (WindowIsIconic(hWnd)) {
  94.         POINTL pt;
  95.     pt.x = 0;
  96.       pt.y = 0;
  97.     GpiMove(hPS, (PPOINTL)&pt);
  98.     pt.x = xIconsize-1;
  99.     pt.y = yIconsize-1;
  100.         GpiBox(hPS, 2L, (PPOINTL)&pt, 0L, 0L);
  101.         pt.x = 0;
  102.         pt.y = 2 * (yIconsize - MWnd.CHeight) / 3;
  103.         GpiCharStringAt( hPS, (PPOINTL)&pt, (LONG)strlen(szIcon), (PCH)szIcon);
  104.     }
  105.     else
  106.     TTYWndPaint(&MWnd, hPS, top, bottom);
  107. }
  108.  
  109. /* 
  110.  * Return TRUE if main window is iconic.
  111.  * This kludge is needed since WinQueryWindowPos is not yet fully implemented.
  112.  */
  113. BOOL NEAR WindowIsIconic(HWND hWnd)
  114. {
  115.  
  116.     RECTL cRect;
  117.  
  118.   /* get the current window client rectangle */
  119.     WinQueryWindowRect(hWnd, (PRECTL)&cRect);
  120.  
  121.   /* compare with size when window is iconic */
  122.     if ((cRect.xRight == xIconsize) && (cRect.yTop == yIconsize))
  123.     return TRUE;
  124.  
  125.     return FALSE;
  126. }
  127.  
  128. /* simple procedure to handle the about box */
  129. MRESULT EXPENTRY AboutBoxProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)
  130. {
  131.  
  132.     switch (msg) {
  133.  
  134.     case WM_COMMAND:
  135.         switch(COMMANDMSG(&msg)->cmd) {
  136.         case DID_OK:
  137.             WinDismissDlg (hDlg, TRUE);
  138.             break;
  139.         default:
  140.             break;
  141.         }
  142.         break;
  143.  
  144.     default:
  145.         return WinDefDlgProc(hDlg, msg, mp1, mp2);
  146.     }
  147.     return FALSE;
  148. }
  149.